var Sequelize = require('sequelize');

var DB_NAME = 'db_weiqi';
var USER = 'root';
var PASSWORD = 'fan0314@';

var sequelize = new Sequelize(DB_NAME, USER, PASSWORD, {
  host: 'localhost',
  port: 3306,
  dialect: 'mysql',
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  },
});

var User = sequelize.define('t_user', {
  username: Sequelize.STRING,
  password: Sequelize.STRING,
  email: Sequelize.STRING
});

var Step = sequelize.define('t_step', {
  roomid: {
    type: Sequelize.INTEGER,
    comment: '房间号'
  },
  x: {
    type: Sequelize.INTEGER,
    comment: '围棋横坐标'
  },
  y: {
    type: Sequelize.INTEGER,
    comment: '围棋纵坐标'
  },
  type: {
    type: Sequelize.STRING,
    comment: 'H-黑 B-白'
  },
  userid: {
    type: Sequelize.INTEGER,
    comment: '用户id'
  }
});

var Room = sequelize.define('t_room', {
  roomname: Sequelize.STRING,
  blackStatus: {
    type: Sequelize.INTEGER,
    defaultValue: 10,
    comment: '黑色状态，10-初始化;20-已入座;30-已就绪;40-已开始;50-已结束;60-已离开'
  },
  whiteStatus: {
    type: Sequelize.INTEGER,
    defaultValue: 10,
    comment: '白色状态，10-初始化;20-已入座;30-已就绪;40-已开始;50-已结束;60-已离开'
  },
  blackUser: {
    type: Sequelize.INTEGER,
    comment: '黑棋id'
  },
  whiteUser: {
    type: Sequelize.INTEGER,
    comment: '白棋id'
  },
  roomStatus: {
    type: Sequelize.INTEGER,
    defaultValue: 10,
    comment: '房间状态。 10-已创建；20-等待中；30-已就坐；40-已开始；40-已结束'
  },
  roomOwner: {
    type: Sequelize.INTEGER,
    comment: '房主'
  },
  roomOwnerName: {
    type: Sequelize.STRING,
    comment: '房主名'
  },
  chessSize: {
    type: Sequelize.INTEGER,
    defaultValue: 19,
    comment: '代表几路棋，9,13,19路'
  },
  letNum: {
    type: Sequelize.INTEGER,
    defaultValue: 0,
    comment: '让子数'
  },
  blackName: {
    type: Sequelize.STRING,
    comment: '白棋用户名称'
  },
  whiteName: {
    type: Sequelize.STRING,
    comment: '黑棋用户名称'
  }
});

(async () => {
  await sequelize.sync({ force: false });
})();

module.exports = {
  User,
  Room,
  Step
};


